#import <AppKit/AppKit.h>

static NSString *addTwoDiget(int intValue)
{
	if (intValue<10) {return [NSString stringWithFormat:@"0%d",intValue];
	} else { return [NSString stringWithFormat:@"%d",intValue]; }
}
/* This utility function converts a number of seconds into a NSString with the format tt:mm:ss */
static inline NSString *intToTimeString(int intValue)
{
	int times, minutes, seconds;
	seconds = intValue%60;
	times = (intValue-seconds)/60;
	minutes = times%60;
	times = (times-minutes)/60;
	return [NSString stringWithFormat: @"%@:%@:%@",addTwoDiget(times), addTwoDiget(minutes), addTwoDiget(seconds)];
}
static inline BOOL isSameDay (NSDate *day1, NSDate *day2) {
NSLog(@"isSameDay d1:%@ d2:%@",day1, day2);
	double secondInDay = 60*60*24;
	NSCalendarDate *calday1 = [day1 dateWithCalendarFormat:nil timeZone:nil];
	NSCalendarDate *calday2 = [day2 dateWithCalendarFormat:nil timeZone:nil];
	NSLog(@"isSameDay2 d1:%@ d2:%@",calday1, calday2);
	NSLog(@"fabs:%d",fabs([day1 timeIntervalSinceDate:day2]));
	NSLog(@"fabs:%d",secondInDay);
	if((fabs([day1 timeIntervalSinceDate:day2])<secondInDay) && ([calday1 dayOfWeek] == [calday2 dayOfWeek])) {
		NSLog(@"true");
		return YES;
	} else {
		NSLog(@"false");
		return NO;
		
	}
}